package com.heima.test04;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        //创建数组存储3个汽车对象
        Car[] arr = new Car[3];

        //创建汽车对象，数据来自键盘输入
        Scanner sc = new Scanner(System.in);
        //创建的汽车对象应该放在循环内
        //因为要定义三次，不然就只取了一次值
        for (int i = 0; i < arr.length; i++) {
            Car c = new Car();
            System.out.println("请输入第" + (i + 1) + "个汽车的品牌");
            String brand = sc.next();
            c.setBrand(brand);
            System.out.println("请输入第" + (i + 1) + "个汽车的价格");
            double price = sc.nextDouble();
            c.setPrice(price);
            System.out.println("请输入第" + (i + 1) + "个汽车的颜色");
            String color = sc.next();
            c.setColor(color);

            //把汽车对象c存入数组arr
            arr[i] = c;
        }
        //遍历数组
        for (int i = 0; i < arr.length; i++) {
            Car car = arr[i];
            System.out.println("品牌:" + car.getBrand() + " 价格：" + car.getPrice() + " 颜色：" + car.getColor());
        }
    }
}
